﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.StyleCop;

namespace SPStyleCop.ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string projectPath = @"D:\Users\ut16zn\SPStyleCop\Test\SPStyleCop.UnitTest";
            string filePath = @"D:\Users\ut16zn\SPStyleCop\Test\SPStyleCop.UnitTest\TestData\SPQueryRulesViewField_Violate.cs";
            var settings = Path.GetFullPath("Settings.StyleCop");

            StyleCopConsole console = new StyleCopConsole(settings, false, null, null, true);
            CodeProject project = new CodeProject(0, projectPath, new Configuration(null));

            console.Core.Environment.AddSourceCode(project, filePath, null);

            console.OutputGenerated += OnOutputGenerated;
            console.ViolationEncountered += OnViolationEncountered;
            console.Start(new[] { project }, true);
            console.OutputGenerated -= OnOutputGenerated;
            console.ViolationEncountered -= OnViolationEncountered;
            console.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();

        }


        /// <summary>
        /// Handles generated output.
        /// </summary>
        private static void OnOutputGenerated(object sender, OutputEventArgs e)
        {
            Console.WriteLine(e.Output);
        }

        /// <summary>
        /// Handles encountered violations.
        /// </summary>
        private static void OnViolationEncountered(object sender, ViolationEventArgs e)
        {
            Console.WriteLine("{0}: {1}", e.Violation.Rule.CheckId, e.Message);
        }
    }
}
